home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
borland
/
bgidriv.zip
/
BGI.DOC
next >
Wrap
Text File
|
1989-05-31
|
36KB
|
1,038 lines
-----------------------------
The BGI Driver Toolkit
Creating Device Drivers
for the Borland Graphics Interface
--------------------------------------
Copyright (c) 1988,89 Borland International
Revision 1
May 15, 1989
Introduction
=======================
The Borland Graphics Interface (BGI) is a fast, compact, and
device-independent software package for graphics development built into the
Turbo Pascal, Turbo C, and Turbo Prolog language products. Device
independence is achieved via loadable device-specific drivers called from a
common Kernel. This document describes basic BGI functionality, as well as
the steps necessary to create new device drivers. Accompanying this
document are files containing sample code and other pertinent information.
File Name File Description
BH.C BGI loader header building program source
BH.EXE BGI loader header building program
DEVICE.INC Structure and macro definition file
DEBVECT.ASM Vector table for sample (DEBUG) driver
DEBUG.C Main module for sample driver
MAKEFILE Build file
BUILD.BAT A batch file for MAKE-phobics
BGI Run-time Architecture
=============================
Programs produced by Borland languages create graphics via two entities
acting in concert: the generic BGI Kernel and a device-specific driver.
Typically, an application built with a Borland compiler will include
several device driver files on the distribution disk (extension .BGI) so
that the program can run on various types of screens and printers.
Graphics requests (for example, draw line, draw bar, etc.) are sent by the
application to the BGI Kernel, which in turn makes requests of the device
driver to actually manipulate the hardware.
A BGI device driver is a binary image; that is, a sequence of bytes without
symbols or other linking information. The driver begins with a short
header, followed by a vector table containing the entry points to the
functions inside. The balance of the driver comprises the code and data
required to manipulate the target graphics hardware.
All code and data references in the driver must be near (i.e., small model,
offset only), and the entire driver, both code and data, must fit within
64K. In use, the device driver can count on its being loaded on a paragraph
boundary. The BGI Kernel uses a register-based calling convention to
communicate with the device driver (described in detail below).
BGI Graphics Model
=======================
When considering the functions listed here, keep in mind that BGI performs
most drawing operations using an implicit drawing or tracing color (COLOR),
fill color (FILLCOLOR), and pattern (FILLPATTERN). For example, the
PIESLICE call accepts no pattern or color information, but instead uses the
previously set COLOR value to trace the edge of the slice, and the
previously set FILLCOLOR and FILLPATTERN values for the interior.
For efficiency, many operations take place at the position of the current
pointer, or CP. For example, the LINE routine accepts only a single (x,y)
coordinate pair, using the CP as the starting point of the line and the
passed coordinate pair as the ending point. Many functions (LINE, to name
one) affect CP, and the MOVE function can be used to explicitly adjust CP.
The BGI coordinate system places the origin (pixel 0,0) at the upper
left-hand corner of the screen.
Header Section
=======================
The device header section, which must be at the beginning of the device
driver, is built using macro BGI defined in file DEVICE.INC. The BGI macro
takes the name of the device driver to be built as an argument. For
example, a driver named DEBUG would begin as shown here:
CSEG SEGMENT PARA PUBLIC 'CODE' ; any segment naming may be used
ASSUME DS:CSEG, CS:CSEG ; cs=ds
CODESEG
INCLUDE DEVICE.INC ; include the device.inc file
BGI DEBUG ; declare the device header section
The device header section declares a special entry point known as EMULATE.
If the action of a device driver vector is not supported by the hardware of
a device, the vector entry should contain the entry EMULATE. This will be
patched at load time to contain a jump to the Kernel's emulation routine.
These routines will emulate the action of the vector by breaking down the
request into simpler primitives. For example, if the hardware has the
functionality to draw arc, the arc vector will contain the address
of the routine to dispatch the arc data to the hardware and would
appear as follows:
dw offset ARC ; Vector to the arc routine
If, as is often the case, the hardware doesn't have the functionality to
display arcs, the vector would instead contain the EMULATE vector:
dw EMULATE
The Kernel has emulation support for the following vectors:
BAR Filling 3D rectangles
ARC Elliptical arc rendering
PIESLICE Elliptical pie slices
FILLED_ELLIPSE Filled Ellipses
The Driver Status Table
=======================
BGI requires that each driver contain a Driver Status Table (DST) to
determine the basic characteristics of the device that the driver
addresses. As an example, the DST for a CGA display is shown here:
STATUS STRUC
STAT DB 0 ; Current Device Status (0 = No Errors)
DEVTYP DB 0 ; Device Type Identifier (must be 0)
XRES DW 639 ; Device Full Resolution in X Direction
YRES DW 199 ; Device Full Resolution in Y Direction
XEFRES DW 639 ; Device Effective X Resolution
YEFRES DW 199 ; Device Effective Y Resolution
XINCH DW 9000 ; Device X Size in inches*1000
YINCH DW 7000 ; Device Y Size in inches*1000
ASPEC DW 4500 ; Aspect Ratio = (y_size/x_size) * 10000
DB 8h
DB 8h ; for compatibility, use these values
DB 90h
DB 90h
STATUS ENDS
The BGI interface provides a system for reporting errors to the BGI Kernel
and to the higher level code developed using Borland's language packages.
This is done using the STAT field of the Driver Status Table. This field
should be filled in by the driver code if an error is detected during the
execution of the device installation (INSTALL). The following error codes
are predefined in include file GRAPHICS.H for Turbo C and in the Graphics
unit for Turbo Pascal.
grOk = 0 Normal Operation, No errors
grNoInitGraph = -1
grNotDetected = -2
grFileNotFound = -3
grInvalidDriver = -4
grNoLoadMem = -5
grNoScanMem = -6
grNoFloodMem = -7
grFontNotFound = -8
grNoFontMem = -9
grInvalidMode = -10
grError = -11 Generic Driver Error
grIOerror = -12
grInvalidFont = -13
grInvalidFontNum = -14
grInvalidDeviceNum = -15
The next field in the Device Status Table, DEVTYP, describes the class of
the device that the driver controls; for screen devices, this value is
always 0.
The next four fields, XRES, YRES, XEFRES, and YEFRES contain the number of
pixels available to BGI on this device in the horizontal and vertical
dimensions, minus one. For screen devices, XRES=XEFRES and YRES=YEFRES.
The XINCH and YINCH fields are the number of inches horizontally and
vertically into which the device's pixels are mapped, times 1000. These
fields in conjunction with XRES and YRES permit device resolution (DPI, or
dots per inch) calculation.
Horizontal resolution (DPI) = (XRES+1) / (XINCH/1000)
Vertical resolution (DPI) = (YRES+1) / (YINCH/1000)
The ASPEC (aspect ratio) field is effectively a multiplier/divisor pair
(the divisor is always 10000) that is applied to Y coordinate values to
produce aspect-ratio adjusted images (e.g., round circles). For example,
an ASPEC field of 4500 implies that the application will have to transform
Y coordinates by the ratio 4500/10000 when drawing circles to that device
if it expects them to be round. Individual monitor variations may require
an additional adjustment by the application.
The Device Driver Vector Table
============================